home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6117 < prev    next >
Encoding:
Text File  |  1996-08-05  |  850 b   |  42 lines

  1. Path: wisipc.weizmann.ac.il!news
  2. Newsgroups: comp.lang.c++
  3. Subject: Memory allocation.
  4. Message-ID: <1996Feb10.161530.26449@wisipc.weizmann.ac.il>
  5. From: Kajdan Dimitry <cerlpvk>
  6. Date: Sat, 10 Feb 1996 16:15:30 GMT
  7. Sender: news@wisipc.weizmann.ac.il (News User)
  8. Organization: Technion - Israel Institute of Technology
  9. Content-Type: text/plain; charset=us-ascii
  10. Content-Transfer-Encoding: 7bit
  11. Mime-Version: 1.0
  12. X-Mailer: Mozilla 1.1N (X11; I; OSF1 V3.2 alpha)
  13. X-Url: news://wisipc.weizmann.ac.il/comp.lang.c++
  14.  
  15. I'm a starter so the question may seem stupid.
  16.  
  17. Would someone explain why this program works?
  18.  
  19. int* func()
  20. {
  21.   
  22.   
  23.  int b[10];
  24.    for(int i=0;i<9;i++)
  25.      b[i]=i;
  26.   return b;  
  27. }
  28.  
  29. int main(){
  30.   
  31.  int* x= func();
  32.   
  33.   
  34.   cout<<x[2]<<endl;
  35.   return(1);
  36. }
  37.  
  38. The point is that b is allocated on the stack i.e without "new".
  39.  
  40. Thanks in advance.
  41.  
  42.